package cn.edu.zafu.bigdata.zyf;

public class StaticDemo {
    // 静态变量，用来记录实例的数量
    static int count;

    // 实例变量，存储每个实例的唯一编号
    int id;

    // 静态初始化块
    static {
        count = 0;
        System.out.println("Static block executed");
    }

    // 实例初始化块
    {
        id = count++;
        System.out.println("Instance block executed for ID: " + id);
    }

    // 构造函数
    public StaticDemo() {
        System.out.println("Constructor executed for ID: " + id);
    }

    // 静态方法，显示当前创建了多少个实例
    public static void displayCount() {
        System.out.println("Total instances created: " + count);
    }
}
